/**
 * 
 */
package domain;

import java.util.*;

/**
 * @author it-equipment-selection team
 *
 */
public class ContractTableQuery implements IQuery {

	/* (non-Javadoc)
	 * @see domain.IQuery#productQuery(java.util.Collection)
	 * @returns most voted products Collection
	 */
	public Collection productQuery(Collection products, Collection articles) {
		Collection aux = new ArrayList();
		Iterator ita = articles.iterator();
		while (ita.hasNext()){
			Article a = (Article) ita.next();
			Iterator itp = products.iterator();
			int votos = -1;
			Product paux = null;
			while (itp.hasNext()){
				Product p = (Product) itp.next();
				if (p.getArticle().equals(a) && p.getNumVotes() > votos){
					votos = p.getNumVotes();
					paux = p;
				}
			}
			if (aux!=null)
				aux.add(paux);
		}
		return aux;
	}

}
